<?php

error_reporting (E_ALL | E_STRICT);
date_default_timezone_set ('UTC');

include_once 'ccxt.php';

$keys = array('huobipro'=>array(
						'apiKey'=>'f006fe4c-84e6b5da-d46d867e-58d04',
						'secret'=>'d2d72bd6-a3115666-ace0993f-0c396'
					),
			'okex'=>array(
						'apiKey'=>'f2339b63-9e87-400e-9fe8-76a190efe3b2',
						'secret'=>'9DFE581711DA3B93C5CD144BB5C50F76'
					),
			);


if(!isset($_GET['exchange']))
	die("exchange can't be null");

if(!isset($_GET['market']))
	die("market can't be null");

$exchange_name = $_GET['exchange'];
$market = $_GET['market'];

if(empty($exchange_name))
	die("exchange can't be null");

if(empty($market))
	die("market can't be null");

if(!isset($keys[$exchange_name]))
	die("exchange keys don't exsist");

$apiKey = $keys[$exchange_name]['apiKey'];
$secret = $keys[$exchange_name]['secret'];

$className = "\ccxt\\".$exchange_name;

$exchagne     = new $className    (array (
    'apiKey' => $apiKey,
    'secret' => $secret ,
));


$result = $exchagne->fetch_ticker($market);

$data = array();
$data['exchange'] = $exchange_name ;
$data['market'] = $market;
$data['price'] = $result['bid'];
$data['change'] = $result['percentage'];
$data['volume'] = $result['info']['vol'];
$data['update_time'] = time();	

die(json_encode($data));